package com.xyx.ssm.action;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xyx.ssm.po.Winebrand;
import com.xyx.ssm.service.WinebrandService;
import com.xyx.ssm.util.Page;

@Controller
@RequestMapping(value = "/winebrand")
public class WinebrandAction {
	@Resource
    private WinebrandService winebrandService;
	
	@RequestMapping("/pageView")
	public String pageView(Model model,Integer pageNow,String pageName,String departName){
		Map<String,Object> map =new HashMap<String, Object>();
		//用户名
		map.put("pageName", pageName);
		if(pageNow==null){
			pageNow=1;
		}
		System.out.println(map.toString());
		//1:当前页码
		//1:查询参数
		Page<Map<String,Object>> page =new Page<Map<String,Object>>(pageNow,map,2);
		Page<Map<String,Object>> page1 =winebrandService.findPage(page);
		page1.setParam(map);
		model.addAttribute("page", page1);
	return "wine/winebrandlist";
}
	
	
	
	@RequestMapping("/role")
	public String role(Model model){
		System.out.println("11111111111111111");
	return "wine/role";
}
	

	
	@RequestMapping("/jsons")
	@ResponseBody
	public Map<String,Object> jsons(Model model,Integer iDisplayLength,Integer sEcho,Integer iDisplayStart,String pageName,String departName){
		
		Map<String,Object> map111 =new HashMap<String, Object>();
		//用户名
		map111.put("pageName", "");
		if(sEcho==null){
			sEcho=1;
		}
		if(iDisplayLength==null){
			iDisplayLength=10;
		}
		if(iDisplayStart==null){
			iDisplayStart=1;
		}
		System.out.println(map111.toString());
		//1:当前页码
		//1:查询参数
		Page<Map<String,Object>> page =new Page<Map<String,Object>>(iDisplayStart,map111,iDisplayLength);
		Page<Map<String,Object>> page1 =winebrandService.findPage(page);
		int num=page1.getList().size();
		 Map<String, Object> map = new HashMap<String, Object>();
			map.put("sEcho", sEcho);
			map.put("iTotalRecords", page1.getTotalCount());
			map.put("iTotalDisplayRecords", page1.getTotalCount());
		    map.put("aaData", page1.getList());
			return map;
}

	@RequestMapping("/winebrandadd")
	@ResponseBody
	public Map<String,Object> winebrandadd(String brandname,String branddetail){
		
		Map<String,Object> map =new HashMap<String, Object>();
		//用户名
		
		map.put("brandname", brandname);
		map.put("branddetail", branddetail);
		
		int num=winebrandService.winebrandadd(map);
		
		Map<String,Object> mapjson =new HashMap<String, Object>();
		if(num>0){
			mapjson.put("flag", true);
			mapjson.put("msg", "保存成功！");
		}else{
			mapjson.put("flag", false);
			mapjson.put("msg", "保存失败！");
		}
	 return mapjson;
}
	
	
	@RequestMapping("/winebrandupdate")
	@ResponseBody
	public Map<String,Object> winebrandupdate(Winebrand winebrand){
		
		
		System.out.println("1111--------"+winebrand.toString());
		//用户名
		
		
		int num=1;
		
		Map<String,Object> mapjson =new HashMap<String, Object>();
		if(num>0){
			mapjson.put("flag", true);
			mapjson.put("msg", "保存成功！");
		}else{
			mapjson.put("flag", false);
			mapjson.put("msg", "保存失败！");
		}
	 return mapjson;
}
	
	

	@RequestMapping("/winebranddelete")
	@ResponseBody
	public Map<String,Object> winebranddelete(String ids){
		
		System.out.println("so easy -"+ids);
		int num=0;
		Map<String,Object> mapjson =new HashMap<String, Object>();
		if(num>0){
			mapjson.put("flag", true);
			mapjson.put("msg", "保存成功！");
		}else{
			mapjson.put("flag", false);
			mapjson.put("msg", "保存失败！");
		}
	 return mapjson;
}

	@RequestMapping("/winebranddetail")
	@ResponseBody
	public Map<String,Object> winebranddetail(String id){
		System.out.println("so easy -"+id);
		Map<String,Object> map =new HashMap<String, Object>();
		map.put("id", id);
		map=winebrandService.selectbyid(map);
	 return map;
}

}